<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Smarty.class.php';

class template {
	
	public $theme;
	protected $smarty;
	
	public function __construct()
	{
		$this->smarty = new Smarty();
		$this->smarty->compile_dir = TMPDIR . 'compiled' . DIRECTORY_SEPARATOR;
		$this->theme = core_settings::Get('theme');
		if (!file_exists($this->smarty->compile_dir))
			mkdir($this->smarty->compile_dir);
	}
	
	public function assign($var, $value)
	{
		$this->smarty->assign($var, $value);
	}
	
	public function block($block, $values)
	{
		$this->smarty->append($block, $values);
	}
	
	public function fetch($page) 
	{
		$dir = ROOTDIR . core_settings::Get('themedir') . DIRECTORY_SEPARATOR;
		$this->smarty->template_dir = $dir . $this->theme . DIRECTORY_SEPARATOR;
		$this->assign('themeurl', core_settings::Get('themepath') . $this->theme . '/');
		$this->assign('sitepath', core_settings::Get('sitepath'));
		$arg = array($this);
		core_signal::NewSignal('display', $arg);
		return $this->smarty->fetch($page);
	}

	public function display($page)
	{
		echo $this->fetch($page);
	}
}